package com.only4play.practice.invoice.core.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.only4play.codegen.processor.api.*;
import com.only4play.codegen.processor.controller.GenController;
import com.only4play.codegen.processor.creator.GenCreator;
import com.only4play.codegen.processor.dto.GenDto;
import com.only4play.codegen.processor.entitymapper.GenObjectMapper;
import com.only4play.codegen.processor.mapper.GenMapper;
import com.only4play.codegen.processor.query.GenQuery;
import com.only4play.codegen.processor.service.GenService;
import com.only4play.codegen.processor.service.GenServiceImpl;
import com.only4play.codegen.processor.updater.GenUpdater;
import com.only4play.codegen.processor.vo.GenVo;
import com.only4play.codegen.support.annotation.FieldDesc;
import com.only4play.codegen.support.constants.ValidStatus;
import com.only4play.codegen.support.model.BaseEntity;
import com.only4play.practice.common.enums.ReceiptStatus;
import com.only4play.practice.common.other.CodeValue;
import com.only4play.practice.ordercommon.pay.PayItem;
import lombok.Data;

import java.util.List;

@GenCreator(pkgName = "com.only4play.practice.invoice.api.model.creator")
@GenUpdater(pkgName = "com.only4play.practice.invoice.api.model.updater")
// findById方法
@GenVo(pkgName = "com.only4play.practice.invoice.api.model.vo")
// findByPage方法
@GenQuery(pkgName = "com.only4play.practice.invoice.api.model.query")
@GenCreateRequest(pkgName = "com.only4play.practice.invoice.model.api.request")
@GenUpdateRequest(pkgName = "com.only4play.practice.invoice.model.api.request")
@GenQueryRequest(pkgName = "com.only4play.practice.invoice.model.api.request")
@GenResponse(pkgName = "com.only4play.practice.invoice.api.model.api.response")
@GenDto(pkgName = "com.only4play.practice.invoice.model.dto")
// 生成serviceImpl
@GenObjectMapper(pkgName = "com.only4play.practice.invoice.core.entitymapper")
// 生成serviceImpl
@GenMapper(pkgName = "com.only4play.practice.invoice.core.mapper")
@GenService(pkgName = "com.only4play.practice.invoice.core.service")
@GenServiceImpl(pkgName = "com.only4play.practice.invoice.core.service.impl")

@GenController(pkgName = "com.only4play.practice.invoice.core.controller")
@GenFeign(pkgName = "com.only4play.practice.invoice.feign")
@Data
/*
  订单发票实体（相当于现实中的凭据小票）
  订单完成之后就可以注册票据放到数据库，将来需要开票的时候可以直接查询到该订单的凭据信息，然后进行开票操作
 */
@TableName(autoResultMap = true)
public class OrderReceipt extends BaseEntity {

  @FieldDesc(name = "注册流水号")
  private Long registerFlowNo; // 可以理解为票据号的唯一编码

  // 这三个字段用于将来扩展
  @FieldDesc(name = "业务系统编码 可能是卖衣服的商城 也可能是超市")
  private String bizSystemCode;
  @FieldDesc(name = "交易类型编码")
  private String tradeTypeCode;
  @FieldDesc(name = "交易类型名称")
  private String tradeTypeName;


  @FieldDesc(name = "订单流水号")
  private String orderFlowNo;

  @TableField(typeHandler = JacksonTypeHandler.class)
  @FieldDesc(name = "订单相关属性")
  // 将来可以将所有需要用到的订单属性放到这里进行扩展，企业开票的时候可能根据企业维度开票、可能根据车牌开票、可能根据商品开票等
  // 这些都是不确定的，不确定的形式则可以使用json 格式存储
  private List<CodeValue> orderAttrs;

  @FieldDesc(name = "有效开票金额")
  private Long validAmount;
  @FieldDesc(name = "无效开票金额")
  private Long invalidAmount;

  // 根据支付项配置来决定哪些有效哪些无效
  @FieldDesc(name = "可用开票明细")
  @TableField(typeHandler = JacksonTypeHandler.class)
  private List<PayItem> validList;
  @TableField(typeHandler = JacksonTypeHandler.class)
  @FieldDesc(name = "不可用开票明细")
  private List<PayItem> invalidList;


  @FieldDesc(name = "凭据状态 | 发票状态")
  private ReceiptStatus receiptStatus;

  @FieldDesc(name = "开票企业税务编码")
  private String taxCode;

  private ValidStatus validStatus;

  public void init() {
    setValidStatus(ValidStatus.VALID);
  }

  public void valid(){
    setValidStatus(ValidStatus.VALID);
  }

  public void invalid(){
    setValidStatus(ValidStatus.INVALID);
  }

}
